package com.zksk.portal.controller.section;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zksk.common.core.domain.R;
import com.zksk.common.core.utils.StringUtils;
import com.zksk.common.core.web.controller.BaseController;
import com.zksk.common.log.annotation.Log;
import com.zksk.common.log.enums.BusinessType;
import com.zksk.mbg.admin.domain.Section;
import com.zksk.portal.domain.vo.SectionVo;
import com.zksk.portal.service.section.SectionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 标段信息
 *
 * @author zksk
 */
@Slf4j
@RestController
@RequestMapping("/section")
@Api(tags = "标段信息相关接口")
public class SectionController extends BaseController {

    @Autowired
    private SectionService sectionService;

    /**
     * 获取标段列表
     */
    @Log(title = "标段信息列表查询", businessType = BusinessType.SELECT)
    @ApiOperation(value = "获取标段信息列表")
    @PostMapping("/list")
    public R<Page> list(@RequestBody SectionVo sectionVo){
        //构建分页
        Page<Section> pageInfo = new Page<>(sectionVo.getPageNum(),sectionVo.getPageSize());
        //构建条件
        LambdaQueryWrapper<Section> wrapper = new LambdaQueryWrapper<Section>()
                .like(StringUtils.isNotBlank(sectionVo.getSectionName()), Section::getSectionName, sectionVo.getSectionName())
                .eq(StringUtils.isNotBlank(sectionVo.getProjectTypeName()), Section::getProjectTypeName, sectionVo.getProjectTypeName())
                .eq(StringUtils.isNotBlank(sectionVo.getArea()), Section::getArea, sectionVo.getArea())
                .orderByDesc(Section::getOpenTime);

        Page<Section> page = sectionService.page(pageInfo, wrapper);
        return R.ok(page);
    }

    /**
     * 根据标段id查询标段信息
     */
    @GetMapping(value = "/{id}")
    @ApiOperation(value = "根据标段id查询标段信息")
    public R<Section> selectSection(@PathVariable Long id) {
        return R.ok(sectionService.getById(id));
    }


}
